<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Http\Controllers;

use App\Models\User;
use App\Service\Statistics\StatisticsService;

class UserController extends Controller
{
    public function getUserData($user_id)
    {
        //TODO 钱包 积分 通证 奖励余额 新零售消费 拼单消费 已释放 待释放
        $user = User::query()->find($user_id);
        $Ancestors = $user->queryAncestors()->select(['id', 'name', 'telephone'])->get()->toArray();
        $Statistics = StatisticsService::make();
        $now = now()->toDateTimeString();

        //TODO 钱包 积分 通证
        $UserAccountAmount = $Statistics->geUserAccountAmount($user);
        //TODO 充值
        $getUserRecharge = StatisticsService::make()->getUserRecharge($user);
        //拼团释放通证  拼团待释放通证
        $getKcInfo = StatisticsService::make()->getKcInfo($user);
        //消费
        $consumption = StatisticsService::make()->consumption($user);
        //流水
        $transfer = StatisticsService::make()->transfer($user);
        return view('userDataList', compact(
            'user',
            'UserAccountAmount',
            'getUserRecharge',
            'getKcInfo',
            'consumption',
            'transfer',
            'now',
            'Ancestors'
        ));
    }

    public function getUserInfo()
    {
        return User::with([
            'parent' => function ($query) {
                $query->select('id', 'telephone');
            },
            'pointAccount' => function ($query) {
                $query->select('user_id', 'withdraw_points');
            },
            'beanAccount' => function ($query) {
                $query->select('user_id', 'available_beans');
            },
            'walletAccount' => function ($query) {
                $query->select('user_id', 'balance');
            },
            'rewardAccount' => function ($query) {
                $query->select('user_id', 'available_balance');
            },
            'productOrder',
            'GroupOrder',
            'OrderBeanReward',
        ])
            ->select('telephone', 'id', 'parent', 'contribution_value')
            ->simplePaginate(request('size', 10));
    }
}
